#include<cstdlib>
#define LCCTOOLBOX_DLL_IMPORT_LCCTOOLBOX
#define LCCTOOLBOX_DLL_IMPORT_LENCUCU
#include<ALLINALL.hpp>
#include<lencucuCandy.hpp>
#ifdef _WIN32
#pragma comment(lib,"lencucu")
#endif
using namespace Allinall;
using namespace Lencucu;
using namespace Lencucu::Candy;
using namespace LccToolbox;

allinall* AIA_p=nullptr;
lencucu* lcc_p=nullptr;

__shakeShake_(AIAPtr){
	if(!AIAPtr)
	{	printf("AIAPtr:%p\n",AIAPtr);
		return;
	}
	auto& AIA=*ptras<allinall>(AIAPtr);
	AIA_p=&AIA;

	AIA.mess.surround(smark{"lencucuHolderType"});
	lcc_p=*ptras<lencucu*>(AIA.mess.var_address(mark{"lencucuHolderVar"}));
	if(!lcc_p)
	{	printf("lcc_p:%p\n",lcc_p);
		return;
	}

	auto& Env_p=lcc_p->getRefpEnv();
	auto& GLC_p=lcc_p->getRefpGLC();
	auto& DS_p=lcc_p->getRefpDS();

	UnitLine points;
	points.paintMode=_paint_mode::points;
	points.UNO.alloc(1);
	points.UNO[0].u=3;
	points.UNO[0].n=false;
	points.UNO[0].o=0;
	points.UNO[1].u=3;
	points.UNO[1].n=false;
	points.UNO[1].o=reinterpret_cast<void*>(3*sizeof(float));
	points.stridebyte=6*sizeof(float);
	points.alloc(6*sizeof(float)*10);
	float* temp=points.ptras<float>();
	for(int i=0;i<10;++i){
		temp[i*6+0]=float(rand()%100)/100;
		temp[i*6+1]=float(rand()%100)/100;
		temp[i*6+2]=0;
		temp[i*6+3]=float(rand()%255)/255;
		temp[i*6+4]=float(rand()%255)/255;
		temp[i*6+5]=float(rand()%255)/255;
	}

	DataPacket dpPlay;
	ShaderPacket spPlay;
	dpPlay.unitline_p=&points;
	spPlay.vtx=std::move(AIA.temp.combineStr(AIA.programPath.ptr(),"../../extension/frame_play/carry/vtx.glsl"));
	spPlay.frg=std::move(AIA.temp.combineStr(AIA.programPath.ptr(),"../../extension/frame_play/carry/frg.glsl"));

	readPacket(*DS_p,*GLC_p,dpPlay,spPlay);
	print(dpPlay,spPlay);

	Env_p->render([&]{
		glClear(GL_COLOR_BUFFER_BIT);
		Env_p->waitEvents();
		GLC_p->draw(AIA_AUTO,dpPlay.array);
		Env_p->swapBuffers();
	});
}